package com.lebang.controller.api.earned.book;

import com.lebang.common.MemberLock;
import com.lebang.common.Require;
import com.lebang.feign.ListenBookFeign;
import com.lebang.model.RequestUserInfo;
import com.lebangweb.response.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: ljx
 * @Date: 2020/10/30
 */
@Api(tags = "听书赚")
@RestController
@RequestMapping("/app/book")
public class ListenBookApi {
    @Autowired
    private ListenBookFeign feign;

    /**
     * 添加听书记录
     *
     * @param request
     * @param bookId
     * @param bookMessage
     * @return
     */
    @Require
    @ApiOperation("添加听书记录")
    @PostMapping("/add/history")
    @MemberLock
    public JsonData addHistory(HttpServletRequest request,
                               @ApiParam(name = "听书id") @RequestParam(value = "bookId") String bookId,
                               @ApiParam(name = "听书记录") @RequestParam(value = "bookMessage") String bookMessage) {
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.addHistory(userInfo, bookId, bookMessage);
    }

    /**
     * 获取听书历史记录
     *
     * @param request
     * @return
     */
    @Require
    @ApiOperation("获取听书历史记录")
    @GetMapping("/get/history")
    public JsonData getHistory(HttpServletRequest request,
                               @RequestParam(value = "page") Integer page,
                               @RequestParam(value = "limit") Integer limit) {
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.getHistory(userInfo, page, limit);
    }

    /**
     * 获取最新听书记录
     */
    @Require
    @ApiOperation("获取最新听书记录")
    @GetMapping("/get/newhistory")
    public JsonData getNewHistory(HttpServletRequest request) {
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.getNewHistory(userInfo);
    }

    /**
     * 删除听书历史记录
     *
     * @param request
     * @param bookId
     * @return
     */
    @Require
    @ApiOperation("删除听书历史记录")
    @PostMapping("/del/history")
    public JsonData delHistory(HttpServletRequest request, @ApiParam(name = "听书id") @RequestParam(value = "bookId") String bookId) {
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.delHistory(userInfo, bookId);
    }

    /**
     * 删除所有听书历史记录
     *
     * @param request
     * @return
     */
    @Require
    @ApiOperation("删除所有听书历史记录")
    @PostMapping("/delAll/history")
    public JsonData delAllHistory(HttpServletRequest request) {
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.delAllHistory(userInfo);
    }

    /**
     * 添加听书搜索记录
     *
     * @param request
     * @param content
     * @return
     */
    @Require
    @ApiOperation("添加听书搜索记录")
    @PostMapping("/add/searchrecord")
    @MemberLock
    public JsonData addSearchRecord(HttpServletRequest request, @ApiParam(name = "搜索记录") @RequestParam("content") String content) {
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.addSearchRecord(userInfo,content);
    }

    /**
     * 获取听书搜索记录
     *
     * @param request
     * @return
     */
    @Require
    @ApiOperation("获取听书搜索记录")
    @GetMapping("/get/searchrecord")
    public JsonData getSearchRecord(HttpServletRequest request) {
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.getSearchRecord(userInfo);
    }

    /**
     * 删除听书搜索记录
     *
     * @param request
     * @return
     */
    @Require
    @ApiOperation("删除听书搜索记录")
    @PostMapping("/del/searchrecord")
    public JsonData delSearchRecord(HttpServletRequest request) {
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.delSearchRecord(userInfo);
    }

    /**
     * 获取用户听书分类
     *
     * @param request
     * @return
     */
    @Require
    @ApiOperation("获取用户听书分类")
    @GetMapping("/get/category")
    public JsonData getCategory(HttpServletRequest request) {
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.getCategory(userInfo);
    }

    /**
     * 更新用户听书分类
     *
     * @param request
     * @param category
     * @return
     */
    @Require
    @ApiOperation("更新用户听书分类")
    @PostMapping("/update/category")
    public JsonData updateCategory(HttpServletRequest request, @ApiParam(name = "听书分类") @RequestParam("category") String category) {
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.updateCategory(userInfo,category);
    }

    /**
     * 获取用户解锁章节
     *
     * @param request
     * @param bookId
     * @return
     */
    @Require
    @ApiOperation("获取用户解锁章节")
    @PostMapping("/get/unlockchapters")
    public JsonData getUnlockChapters(HttpServletRequest request, @ApiParam(name = "听书id") @RequestParam("bookId") String bookId) {
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.getUnlockChapters(userInfo,bookId);
    }

    /**
     * 用户解锁章节
     *
     * @param request
     * @param bookId
     * @param chapters
     * @return
     */
    @Require
    @ApiOperation("用户解锁章节")
    @PostMapping("/unlock/chapters")
    @MemberLock
    public JsonData unlockChapters(HttpServletRequest request,
                                   @ApiParam(name = "听书id") @RequestParam("bookId") String bookId,
                                   @ApiParam(name = "解锁章节") @RequestParam("chapters") String chapters) {
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.unlockChapters(userInfo,bookId,chapters);
    }


}
